package com.lx.idgenerator.autoconfigure;

import com.baomidou.mybatisplus.autoconfigure.MybatisPlusPropertiesCustomizer;
import com.lx.idgenerator.adaper.MysqlLeafInfoService;
import com.lx.idgenerator.config.MpPropertiesCustomizer;
import com.lx.idgenerator.segement.leaf.ILeafInfoService;
import com.lx.idgenerator.service.ILeafNodeService;
import com.lx.idgenerator.service.impl.LeafNodeServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;

/**
 * @author lX
 * @version JDK 8
 * @className MysqlConfiguration (此处以class为例)
 * @date 2024/11/10
 * @description TODO
 */
@ConditionalOnProperty(prefix = "id.generator.segment.storage",name = "type",havingValue = "mysql")
public class MysqlConfiguration {

    /**
     * 注入查询节点服务
     * @return
     */
    @Bean
    public ILeafNodeService leafNodeService(){
        return new LeafNodeServiceImpl();
    }



    @Bean
    public MybatisPlusPropertiesCustomizer MybatisPlusPropertiesCustomizer(){
        return new MpPropertiesCustomizer();
    }

    /**
     * 基于Mysql存储 注入相关Bean
     * @param leafNodeService
     * @return
     */
    @Bean
    public ILeafInfoService mysqlLeafInfoService(@Autowired ILeafNodeService leafNodeService){
        return new MysqlLeafInfoService(leafNodeService);
    }
}
